//home模块仓库
//接口
import {reqCategoryList,reqCatBannerList,reqCatfloorList} from '@/api'

const state = {
    //state中的数据默认初始值，数据类型根据接口返回值定
    //home仓库存储三级菜单数据
    categoryList:[],
    //轮播图
    bannerList:[],
    //floor
    floorList:[]
}
//修改state中的数据
const mutations = {
    CATEGORYLIST(state,categoryList){
        state.categoryList =categoryList
    },
    GETBANNERLIST(state,bannerList){
        state.bannerList = bannerList
    },
    GETFLOORLIST(state,floorList){
        state.floorList = floorList
    }
}
//响应组件中的动作
const actions = {
    //通过api里的接口函数调用，向服务器发送请求，获取数据
    async categoryList({commit}){
        let result = await reqCategoryList()
        //promise回调成功则
        if(result.code == 200){
            //commit方法第一个是mutations里的函数，第二个是数据
            //到这里会执行mutations里的CATEGORYLIST
            commit("CATEGORYLIST",result.data)
        }
    },
    //获取首页轮播图数据
    async getBannerList({commit}){
        let result = await reqCatBannerList()
        if(result.code == 200){
            commit('GETBANNERLIST',result.data)
        }
    },
    //获取floor数据
    async getfloorList({commit}){
        let result = await reqCatfloorList()
        if(result.code == 200){
            commit('GETFLOORLIST',result.data)
        }
    }
}
const getters = {}
export default {
    state,
    mutations,
    actions,
    getters
}